import React, { Component, createRef, useRef } from "react";
function GetDomFun() {
  const iptRef = useRef(null);
  return (
    <>
      <input ref={iptRef} type="text" />
      <button onClick={() => console.log(iptRef.current.value)}>获取dom</button>
    </>
  );
}

export default function GetDom() {
  return (
    <>
      <h1>类组件</h1>
      <GetRef></GetRef>
      <h1>函数组件</h1>
      <GetDomFun></GetDomFun>
    </>
  );
}
class GetRef extends Component {
  constructor(props) {
    super(props);
  }
  divRef = createRef();
  render() {
    return (
      <>
        <div ref={this.divRef}>这是一个dom</div>
        <button onClick={() => console.log(this.divRef.current.textContent)}>
          打印dom
        </button>
      </>
    );
  }
}
